package model.semantics;

import model.State;
import model.parser.ParserException;

public class PrintNode<T> extends Node<T> {
    private VariableNode<T> myNodeToPrint;

    public PrintNode(Node<T> nodeToPrint) {
        if (!(nodeToPrint instanceof VariableNode)) {
            throw ParserException.BAD_ARGUMENTS;
        }
        myNodeToPrint = (VariableNode<T>) nodeToPrint;
    }

    // Print a variable.
    @Override
    public T evaluate(State<T> state) {
        System.out.println(state.getAssignment(myNodeToPrint.getLabel()));

        return state.getDefaultValue().evaluate(state);
    }

}
